/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pop3proxy.logging;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

class FileLogger implements Logger {
    OutputStreamWriter logFile;
    DateFormat date = new SimpleDateFormat("HH:mm:ss");
    
    FileLogger(String filename) {
        try {
            File f = new File(filename);
            if (!f.exists())
                f.createNewFile();
            logFile = new OutputStreamWriter(new FileOutputStream(filename, true));
            logFile.write("\nSession gestartet um: " + new Date() + "\n");
        } catch (IOException ex) {
            System.err.println("Logger konnte nicht initalisiert werden!");
        }        
    }

    @Override
    public void log(String what) {
        try {
            logFile.write("<" + date.format(new Date()) + "> " + what + "\n");
            logFile.flush();
        } catch (IOException ex) {}
    }
}
